package org.ala.tiktools.generator.mybatis.creator.dao;

import freemarker.template.TemplateException;
import org.ala.tiktools.generator.mybatis.config.info.Part;
import org.ala.tiktools.generator.mybatis.creator.AbstractCreator;
import org.ala.tiktools.generator.mybatis.creator.entity.EntityInfo;
import org.ala.tiktools.generator.mybatis.creator.entity.fields.EntityFieldsInfo;
import org.ala.tiktools.generator.mybatis.creator.order_by.OrderByInfo;
import org.ala.tiktools.generator.mybatis.creator.query.QueryInfo;
import org.ala.tiktools.generator.mybatis.dbinfo.TableInfo;
import org.ala.tiktools.generator.mybatis.tools.Tools;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * @author ala
 * @date 2024-12-31 16:50
 */
public class DaoCreator extends AbstractCreator {


    public DaoInfo create(Part p, TableInfo t, EntityInfo e, QueryInfo q, OrderByInfo ob, EntityFieldsInfo fe) throws TemplateException, IOException {
        DaoInfo d = DaoInfo.build(p, t, e, q, ob, fe);

        Map<String, Object> dataMeta = new HashMap<>();
        dataMeta.put("d", d);

        String out = d.getPkg();
        out = this.getOutRootPath() + out.replaceAll("\\.", "/");
        Tools.existsAndMakeDirs(out);
        out = out + "/" + d.getClassName() + ".java";

        output("Dao.ftl", dataMeta, out);

        System.out.println("生成EDao类. path:" + out);
        return d;
    }
}
